<?php
	require_once("../conexion/conexion.php");
    require_once("../Mantenedores/cliente.php");
	require_once("../Funciones/funciones_publicas.php");
    
    $cli = new Cliente();
	$fun = new funciones_publicas();

	if(isset($_GET['num']))
	{ $facNum = $_GET['num'];}
	if(isset($_GET['fecha']))
	{ $fechaFactura = $_GET['fecha'];}
	
	$fecha = explode("/",$fechaFactura);
	$dia = $fecha[0];
	$mes = $fecha[1];
	$agno = $fecha[2];
    $fecha = "$fecha[2]-$fecha[1]-$fecha[0]";
	$palMes = $fun->SeleccionaMes($mes);
   
	//se busca los datos del cliente
	$con = new Conexion();
	$con2 = $con->conexionBD("fpproduccion");
	$sql="select 
				CliRSocial,
				CliDireccion,
				CliGiro,
				ConVentaDescrip,
				factura.CliRut,
				CliRegion,
				CliFono,
				AENombre
				
				from clientes 
				inner join factura on 
				factura.CliRut=clientes.CliRut 
				inner join condicionventa on 
				condicionventa.ConVentaCod=factura.ConVentaCod
				inner join areaextraccion on
				areaextraccion.AECod=factura.AECod
				
				where FacCod='".$facNum."'";
	$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
	$datos =   mysql_fetch_array($res);
	$con->cerrarBD();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<!--<link href="../Estilos/global.css" rel="stylesheet" type="text/css" />-->
<link href="../Estilos/local.css" rel="stylesheet" type="text/css" />
<script src="../include_js/jquery.js" type="text/javascript"></script>
<style>

table.estilo
{
 border-collapse:collapse;
 color:#6593C0;
 font:normal 12px verdana, arial, helvetica, sans-serif;
 border:1px solid #6593C0;
}
label.texto
{
  font:verdana;
  font-size:14px;
  color:#000000;
}
table.encabezado
{
	text-transform:uppercase;
	text-align:center;
 	border-collapse:collapse;
 	color:#0066FF;
 	font:normal 12px verdana, arial, helvetica, sans-serif;
}
thead tr th, tfoot tr th {
 background:#89C0C7;
 color:#FFFFFF;
 padding:3px 10px 3px 10px;
 text-align:center;
 text-transform:uppercase;
}
.Normal
{
border:1px solid #0066FF;
}
.caja{
font-family: Verdana;
font-size: 8pt;
font-style: normal;
color: #000000;
/*line-height: 14pt;*/
text-decoration: none;
background-color: #FFFFFF;
border: 0px;
border-left: 0px solid #6C6C6C;
border-right: 0px solid #6C6C6C;
}
.area
{
font-family:Verdana;
font-size:9pt;
color: #000000;
border-style:solid; 
border-top-width:0px; 
border-right-width:0px; 
border-bottom-width:0px;
border-left-width:0px;
overflow:hidden;;
}
.encabezado
{
	font:normal 12px verdana, arial, helvetica, sans-serif;
 	color:#000000;
}
.totales
{
	font:normal 12px verdana, arial, helvetica, sans-serif;
 	color:#000000;
}
.caja2{
font-family: Verdana;
font-size: 10pt;
font-style: normal;
color: #000000;
/*line-height: 14pt;*/
text-decoration: none;
background-color: #FFFFFF;
border: 0px;
border-left: 0px solid #6C6C6C;
border-right: 0px solid #6C6C6C;
text-align:right;
}
.texto
{
	font:verdana;
	font-size:14px;
 	color:#000000;
	text-align:center;
}
.datos
{
	font:verdana;
    font-size:12px;
    color:#000000;
	text-align:center;
}
.resp
{
	font:verdana;
    font-size:14px;
    color:#000000;
}
</style>
<script>
function window.onbeforeprint()
{ 
	boton=document.getElementById("btn_Imprimir");
	boton.style.display = 'none'; 
} 
function window.onafterprint()
{ 
	boton=document.getElementById("btn_Imprimir");
	boton.style.display = 'block'; 
}

function Imprimir()
{
	window.print()
}
</script>
</head>

<body>
<form name="form_VentanFactura" id="form_VentanFactura" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
  <td align="center"><input name="btn_Imprimir" id="btn_Imprimir" type="button" onclick="Imprimir();" value="Imprimir" /></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2" style="height:175px;">&nbsp;</td>
  </tr>
  <tr>
    <td width="79%">&nbsp;</td>
    <td width="21%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2"><div style="padding-left:50px"><label class="texto"><?php echo $dia;?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label class="texto"><?php echo $palMes;?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label class="texto"><?php echo $agno;?></label></div></td>
  </tr>
  <tr>
    <td><div style="padding-left:50px; padding-top:12px;"><label class="datos"><?php echo $datos[0];?></label></div></td>
    <td><div style="padding-top:12px;"><label class="texto"><?php echo $datos[4];?></label></div></td>
  </tr>
  <tr>
    <td><div style="padding-left:50px;padding-top:12px;"><label class="datos"><?php echo $datos[1];?></label></div></td>
    <td><div style="padding-top:12px;"><label class="texto"><?php echo $datos[5];?></label></div></td>
  </tr>
  <tr>
    <td><div style="padding-left:50px;padding-top:12px;"><label class="datos"><?php echo $datos[2];?></label></div></td>
    <td><div style="padding-top:12px;"><label class="texto"><?php echo $datos[6];?></label></div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><div style="padding-top:12px;"><label class="texto"><?php echo $datos[3];?></label></div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

<!--tabla que contiene la glosa de la factura   <div id="item" style="display:block"></div>-->
<?php
//buscamos el nombre del area de extraccion	
	$con3 = new Conexion();
	$con4 = $con3->conexionBD("fpproduccion");
	$sql = "select AENombre from areaextraccion where AECod='".$area."'";
	$resultado = mysql_query($sql) or die ($con3->error_mysql("Error en la consulta".mysql_error()));
	$nom = mysql_fetch_array($resultado);
	$con3->cerrarBD();
?>
<div style="height:15px"></div>
<div style="padding-left:0px">
<table width="100%" cellpadding="4" cellspacing="0" border="0">
<tr>
	<td width="12%">&nbsp;</td>
	<td width="56%">&nbsp;</td>
	<td width="15%">&nbsp;</td>
	<td width="17%">&nbsp;</td>
</tr>
<?php
			$sumatoria=0;
			//PSMB
			$con = new Conexion();
			$con2 = $con->conexionBD("fpproduccion");
			$sql = "select FacPsmb,FacPorcentaje from factura where FacFecha='".$fecha."' and CliRut='".$datos[4]."' and FacCod='".$facNum."'";
			$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
			while($row = mysql_fetch_array($res))
			{
				$cadena = "Muestreos y analisis muestras Programa de Moluscos Bivalvos PSMB, Area ".$datos[7]." mes ".$palMes." del ".$agno.", correspondiente a un % ".$row['FacPorcentaje']."";
				//$cadena .= "PSMB, Area ".$datos[7]." mes ".$palMes." del ".$agno.", correspondiente ";
				//$cadena .= "a un % ".$row['FacPorcentaje']."";
					echo "<tr>";
					echo "<td width='12%' style='text-align:left;padding-left:20px;vertical-align:top;'>1</td>";
					echo "<td width='56%' class='resp'><div style='width:350px;'>".$cadena."</div></td>";
					echo "<td width='15%' style='text-align:right;padding-right:30px;vertical-align:top;'>".number_format ($row['FacPsmb'],0,',','.')."</td>";
					echo "<td width='17%' style='text-align:right;padding-right:30px;vertical-align:top;'>".number_format ($row['FacPsmb'],0,',','.')."</td>";
					echo "</tr>";
					$sumatoria = $sumatoria + $row['FacPsmb'];
			}
			$con->cerrarBD();
			
			//valores del muestreo
			$con = new Conexion();
			$con2 = $con->conexionBD("fpproduccion");
			$sql = "select FacCantMuestreo,FacPorcentaje,FacUFMuestreo,FacUF,FacTotalMuestreo from factura where FacFecha='".$fecha."' and CliRut='".$datos[4]."' and FacCod='".$facNum."'";
			$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
			while($row = mysql_fetch_array($res))
			{
				$unitario = ($row['FacUFMuestreo']*$row['FacUF']);
				$unitario = round($unitario);
				$total = ($row['FacPorcentaje']*$row['FacTotalMuestreo'])/100;
				$total = round($total);
				echo "<tr>";
				echo "<td width='12%' style='text-align:left;padding-left:20px;vertical-align:top;'>".$row['FacCantMuestreo']."</td>";
				echo "<td width='56%' class='resp'>Valor del Muestreo Fishing, correspondiente a un %".$row['FacPorcentaje']."</td>";
				echo "<td width='15%' style='text-align:right;padding-right:30px;vertical-align:top;'>".number_format ($total,0,',','.')."</td>";
				echo "<td width='17%' style='text-align:right;padding-right:30px;vertical-align:top;'>".number_format ($total,0,',','.')."</td>";
				echo "</tr>";
				$sumatoria = $sumatoria + $total;
			}
			$con->cerrarBD();
			
			//se cargan los otros valores
			$con = new Conexion();
			$con2 = $con->conexionBD("fpproduccion");
			$sql = "select ItemFacCant,ItemFacGlosa,ItemFacUnitario,ItemFacTotal,FacPorcentaje from itemfactura inner join factura on factura.FacCod=itemfactura.FacCod where factura.FacFecha='".$fecha."' and factura.CliRut='".$datos[4]."' and itemfactura.FacCod='".$facNum."'";
			$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
			while($row = mysql_fetch_array($res))
			{
					$total = ($row['FacPorcentaje']*$row['ItemFacTotal'])/100;
					$total = round($total);
					echo "<tr>";
					echo "<td width='12%' style='text-align:left;padding-left:20px;vertical-align:top;'>".$row[0]."</td>";
					echo "<td width='56%' class='resp'>".$row[1]."</td>";
					echo "<td width='15%' style='text-align:right;padding-right:30px;vertical-align:top;'>".number_format ($total,0,',','.')."</td>";
					echo "<td width='17%' style='text-align:right;padding-right:30px;vertical-align:top;'>".number_format ($total,0,',','.')."</td>";
					echo "</tr>";
					$sumatoria = $sumatoria + $total;
			}
			$con->cerrarBD();
			
			$subTotal = $sumatoria;
			$iva = round($subTotal*0.19);
			$total = ($subTotal+$iva);
			$pal=$fun->numletras($total);
			?>
</table>
</div>
<div style="position:absolute; top:710px; left:80px; width:350px">DEPOSITAR EN CUENTA CTE N&deg; 60310391 BANCO BCI A FISHING PARTNERS LTDA</div>
<div style="position:absolute; top:850px; left:20px"><textarea name="txtPalabras" cols="70" rows="3" class="area"><?php echo $pal;?></textarea></div>
<div style="position:absolute; top:860px; left:570px;"><input name="txtSubTotal" type="text" class="caja2" readonly="true"  size="12" value="<?php echo number_format ($subTotal,0,',','.')?>"/></div>
<div style="position:absolute; top:890px; left:570px;"><input name="txtIVA" type="text" class="caja2" readonly="true" size="12" value="<?php echo number_format ($iva,0,',','.')?>"/></div>
<div style="position:absolute; top:920px; left:570px;"><input name="txtTotal" type="text"  class="caja2" readonly="true" size="12" value="<?php echo number_format ($total,0,',','.')?>" /></div>

</form>
</body>
</html>